Specifying User Dictionaries

Use of user dictionaries with RapidSpell Web can be on a one user dictionary for all users, or one user dictionary per user or one user dictionary per group basis. The user dictionary file path is specified in the UserDictionaryFile property of the RapidSpellWebLauncher/RapidSpellWInline control. This property specifies the file path to the user dictionary file on the server, and since this property can be specified simply and dynamically using a 'DataBind', the developer has total control over which dictionary file is used for a user. Therefore it is up to the developer to manage a user's session and retrieve the path to a particular user's/group's dictionary file, if required.

User dictionaries are simple text files, they contain a list of words, one per line, and are written to when the user clicks the 'Add' button. If the user dictionary file doesn't exist, it is created. If the user dictionary file cannot be accessed (due to an invalid path, or insufficient file access permission) then the 'Add' button is not displayed.

User Dictionary Strategy

It is often desirable to give each user their own user dictionary - in order to implement this it is clear that the application must use some sort of user session management (otherwise it is impossible to tell users apart). Given this general requirement it is simple to maintain separate user dictionaries for each user. By creating a directory for user dictionaries and making each dictionary file name dependant on a unique user identifier (perhaps their username, or a database key) each user is given their own file, and at run-time the UserDictionaryFile property can be set accordingly (using a DataBind, or accessing the property in codebehind).

Eg. your application has a user with username "joe_user" (for simplicity we will assume that user names cannot contain characters that are illegal in filenames). A directory off the application directory called "user-dictionaries" is created, the ASP_NET process has permission to write to it. All that is necessary is to set the UserDictionaryFile property;

[Code-behind]
RapidSpellWebLauncher.UserDictionaryFile = MapPath("user-dictionaries/" + userName + ".txt")
or
RapidSpellWInline.UserDictionaryFile = MapPath("user-dictionaries/" + userName + ".txt")

Code Example Using DataBind

Page containing the RapidSpellWebLauncher control

<%@ Register TagPrefix="RapidSpellWeb" Namespace="Keyoti.RapidSpell"
Assembly="Keyoti.RapidSpellWeb" %>
<%@ Page Language="C#" Debug="true"%>
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML>
    <HEAD>
    <script language="C#" runat="server">
    //set the user dictionary file, this path could be obtained
    //dynamically if the user has their own file.
    String userDicFile = "C:\\Inetpub\\wwwroot\\rapidSpellWeb\\userDict.txt";
    //on page load, bind the data
    void Page_Load(Object sender, EventArgs e) {
        Page.DataBind();
    }
        </script>
    </HEAD>
    <BODY>
        <form runat="server" method='post' id="form1">
            <textarea id="sourceTextBox" name="sourceTextBox" wrap='true'
cols='40' rows='10'>This is some sample text with daliberate spelling errars</
textarea>
            <br>
            <RapidSpellWeb:RapidSpellWebLauncher
            id="rapidSpellWebLauncher" runat="server"
            TextComponentName="sourceTextBox"
            Mode="popup"
            UserDictionaryFile="<%# userDicFile %>"
            RapidSpellWebPage="PopUp.aspx"
            />

        </form>
    </BODY>
</HTML>

In this example the user dictionary is specified in the string userDicFile which is passed to the UserDictionaryFile property of the RapidSpellWebLauncher control using the <%# .... %> tags. The Page.DataBind() method is called when the page loads, which binds the value of userDicFile to the property UserDictionaryFile. The string was specified statically, but it could easily have come from a database, or session control object.